/**
 * @description: 路由配置入口
 */

import NProgress from "nprogress";
import "nprogress/nprogress.css";
NProgress.configure({ showSpinner: false });

import { createRouter, createWebHistory,RouteRecordRaw } from "vue-router";

/* SecurityLayout */
import SecurityLayout from "@/layouts/SecurityLayout.vue";

/* MemberLayout */
import MemberLayoutRoutes from "@/layouts/MemberLayout/routes";
import MemberLayout from "@/layouts/MemberLayout/index.vue";


/* UserLayout */
import UserLayoutRoutes from "@/layouts/UserLayout/routes";
import UserLayout from "@/layouts/UserLayout/index.vue";


// 配置路由
const routes: RouteRecordRaw[] = [
	// MemberLayout 必须放在最上方，因为 redirect: "/home"
	{
		path: "/",
		component: SecurityLayout,
		children: [
			{
				path: "/",
				redirect: "/home",
				component: MemberLayout,
				children: MemberLayoutRoutes,
			},
		],
	},
	{
		path: "/",
		component: UserLayout,
		children: UserLayoutRoutes,
	},

	{
		path: "/:pathMatch(.*)*",
		component: () => import("@/pages/404/index.vue"),
	},
];

const router = createRouter({
	routes: routes,
	history: createWebHistory(import.meta.env.BASE_URL),
	scrollBehavior:() =>( { left: 0, top: 0 }),
});

router.afterEach(() => {
	// finish progress bar
	NProgress.done();
});

export default router;
